﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

using BLL;
using DAL;
using Models;
using System.Data;
using System.Text;
using System.Xml;
using Web.Old_App_Code;

public partial class backstage_basic_set : System.Web.UI.Page
{
    // Fields
    protected string basicSetXmlPath = "/cn/xml/website_set.xml";
    protected string customerCodePath = "/cn/xml/customer_code.txt";
   
    protected string templateXmlPath = "/xml/template.xml";
    

    // Methods
    private void BasicSetBind()
    {
        try
        {
            XmlElement element;
            string attribute = "";
            XmlDocument document = new XmlDocument();
            document.Load(base.Server.MapPath(this.templateXmlPath));
            XmlNodeList childNodes = document.SelectSingleNode("templateCss").ChildNodes;
            foreach (XmlNode node in childNodes)
            {
                element = (XmlElement)node;
                if (element.GetAttribute("isShow") == "true")
                {
                    attribute = element.GetAttribute("cssSrc");
                    break;
                }
            }
            document.Load(base.Server.MapPath(this.basicSetXmlPath));
            XmlNodeList list2 = document.SelectSingleNode("set").ChildNodes;
            foreach (XmlNode node in list2)
            {
                element = (XmlElement)node;
                switch (element.Name)
                {
                    case "logo":
                        this.imgLogo.Src = attribute + element.GetAttribute("src");
                        this.lblLogo.InnerText = "图片大小：" + element.GetAttribute("width") + "*" + element.GetAttribute("height") + " 分辨率：72像素 格式：jpg,bmp,gif,png";
                        break;

                    case "service_tel":
                        this.imgServiceTel.Src = attribute + element.GetAttribute("src");
                        this.lblServiceTel.InnerText = "图片大小：" + element.GetAttribute("width") + "*" + element.GetAttribute("height") + " 分辨率：72像素 格式：jpg,bmp,gif,png";
                        break;

                    case "cn_enterprise_name":
                        this.txtCnEnterpriseName.Value = element.GetAttribute("value");
                        break;

                    case "en_enterprise_name":
                        this.txtEnEnterpriseName.Value = element.GetAttribute("value");
                        break;

                    case "cn_enterprise_sort_name":
                        this.txtCnEnterpriseSortName.Value = element.GetAttribute("value");
                        break;

                    case "en_enterprise_sort_name":
                        this.txtEnEnterpriseSortName.Value = element.GetAttribute("value");
                        break;

                    case "cn_keword":
                        this.txtCnKeyword.Value = element.GetAttribute("value");
                        break;

                    case "en_keword":
                        this.txtEnKeyword.Value = element.GetAttribute("value");
                        break;

                    case "cn_title":
                        this.txtCnTitle.Value = element.GetAttribute("value");
                        break;

                    case "en_title":
                        this.txtEnTitle.Value = element.GetAttribute("value");
                        break;

                    case "cn_description":
                        this.txtCnDescription.Value = element.GetAttribute("value");
                        break;

                    case "en_description":
                        this.txtEnDescription.Value = element.GetAttribute("value");
                        break;

                    case "copyright":
                        this.txtCopyright.Value = element.GetAttribute("value");
                        break;

                    //case "domain_web_site":
                    //    this.txtDomainweb.Value = element.GetAttribute("value");
                    //    break;

                    case "icp_record_number":
                        this.txtIcpRecordNumber.Value = element.GetAttribute("value");
                        break;

                    case "enterprise_email":
                        this.txtEnterpriseEmail.Value = element.GetAttribute("value");
                        break;

                    case "telephone":
                        this.txtTelephone.Value = element.GetAttribute("value");
                        break;

                    case "fax":
                        this.txtFax.Value = element.GetAttribute("value");
                        break;
                }
            }
            this.txtaCutomerCode.Value = File.ReadAllText(base.Server.MapPath(this.customerCodePath));
        }
        catch
        {
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            XmlElement element;
            string attribute = "";
            XmlDocument document = new XmlDocument();
            document.Load(base.Server.MapPath(this.templateXmlPath));
            XmlNodeList childNodes = document.SelectSingleNode("templateCss").ChildNodes;
            foreach (XmlNode node in childNodes)
            {
                element = (XmlElement)node;
                if (element.GetAttribute("isShow") == "true")
                {
                    attribute = element.GetAttribute("cssSrc");
                    break;
                }
            }
            document.Load(base.Server.MapPath(this.basicSetXmlPath));
            XmlNodeList list2 = document.SelectSingleNode("set").ChildNodes;
            if (this.fileLogo.PostedFile.FileName != "")
            {
                element = (XmlElement)document.SelectSingleNode("set/logo");
                this.fileLogo.PostedFile.SaveAs(base.Server.MapPath(attribute + element.GetAttribute("src")));
            }
            if (this.fielServiceTel.PostedFile.FileName != "")
            {
                element = (XmlElement)document.SelectSingleNode("set/service_tel");
                this.fielServiceTel.PostedFile.SaveAs(base.Server.MapPath(attribute + element.GetAttribute("src")));
            }
            ((XmlElement)document.SelectSingleNode("set/cn_enterprise_name")).SetAttribute("value", this.txtCnEnterpriseName.Value);
            ((XmlElement)document.SelectSingleNode("set/en_enterprise_name")).SetAttribute("value", this.txtEnEnterpriseName.Value);
            ((XmlElement)document.SelectSingleNode("set/cn_enterprise_sort_name")).SetAttribute("value", this.txtCnEnterpriseSortName.Value);
            ((XmlElement)document.SelectSingleNode("set/en_enterprise_sort_name")).SetAttribute("value", this.txtEnEnterpriseSortName.Value);
            ((XmlElement)document.SelectSingleNode("set/cn_keword")).SetAttribute("value", this.txtCnKeyword.Value);
            ((XmlElement)document.SelectSingleNode("set/en_keword")).SetAttribute("value", this.txtEnKeyword.Value);
            ((XmlElement)document.SelectSingleNode("set/cn_title")).SetAttribute("value", this.txtCnTitle.Value);
            ((XmlElement)document.SelectSingleNode("set/en_title")).SetAttribute("value", this.txtEnTitle.Value);
            ((XmlElement)document.SelectSingleNode("set/cn_description")).SetAttribute("value", this.txtCnDescription.Value);
            ((XmlElement)document.SelectSingleNode("set/en_description")).SetAttribute("value", this.txtEnDescription.Value);
            ((XmlElement)document.SelectSingleNode("set/copyright")).SetAttribute("value", this.txtCopyright.Value);
           // ((XmlElement)document.SelectSingleNode("set/domain_web_site")).SetAttribute("value", this.txtDomainweb.Value);
            ((XmlElement)document.SelectSingleNode("set/icp_record_number")).SetAttribute("value", this.txtIcpRecordNumber.Value);
            ((XmlElement)document.SelectSingleNode("set/enterprise_email")).SetAttribute("value", this.txtEnterpriseEmail.Value);
            ((XmlElement)document.SelectSingleNode("set/telephone")).SetAttribute("value", this.txtTelephone.Value);
            ((XmlElement)document.SelectSingleNode("set/fax")).SetAttribute("value", this.txtFax.Value);
            document.Save(base.Server.MapPath(this.basicSetXmlPath));
            File.WriteAllText(base.Server.MapPath(this.customerCodePath), this.txtaCutomerCode.Value);
            base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新成功！\");location.href=\"basic_set.aspx\";</script>");
        }
        catch
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "message", "<script language=\"javascript\" defer>alert(\"更新失败！\");</script>");
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if ((HttpContext.Current.Session["admin_user"] == null) && (HttpContext.Current.Session["language_version"] == null))
        {
            base.ClientScript.RegisterStartupScript(base.GetType(), "sJs", "top.location=\"login.html\";", true);
        }
        if (!base.IsPostBack)
        {
            this.BasicSetBind();
        }
    }

}